import {Component, HostListener, ElementRef, Renderer, ViewContainerRef, OnInit} from '@angular/core';
import 'rxjs/add/operator/merge';
import {Router} from "@angular/router";
import {User} from "./project/entity/User";
import {UserService} from "./user/service/user.service";
import {NgForm} from "@angular/forms";
import {FrontUser} from "./user/entity/User";
import {LoginService} from "./user/service/login.service";
import {CommonIp} from "./user/entity/Ip";


@Component({
  selector: 'app-root',
  templateUrl: './personal-login.html',

})
export class AppLoginComponent extends CommonIp implements OnInit {

  user:FrontUser=new FrontUser();
  userMessage:FrontUser;
  public data:string;

  constructor(public loginservice:LoginService,public userservice:UserService){
    super();
  }
  onSubmit(usernameFrom:NgForm, user:FrontUser){

        this.submitUser(user);






  }

  public submitUser(user:FrontUser){
    this.userservice.getPersoanlLogin(user)
    ;
  }

  public  code = 0;

  ngOnInit(): void {
    this.HiddenLeftProgram();
    this.generateValideCode();
  }

  private generateValideCode() {
    let oldRandom = this.user.random;
    this.user.random = Date.now().toString(36)
    +(Math.floor(Math.random() * 100000000) + 100000000).toString();
    let randomRequest = this.userIp + "/servlet/validateCodeServlet?" + Math.random() + "&random=" + this.user.random+"&oldRandom="+oldRandom;
    document.getElementById("codes").setAttribute("src", randomRequest);
  }
  public changeValideCode(){
    this.generateValideCode();
  }



}
